package cn.js.sip.rat.system.service.impl;

import cn.js.sip.rat.system.entity.SysUserEntity;
import cn.js.sip.rat.system.mapper.SysUserMapper;
import cn.js.sip.rat.system.page.TableDataInfo;
import cn.js.sip.rat.system.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName: cn.js.sip.rat.system.service.impl
 * @Description: TODO
 * @author: xuxiaoli
 * @Date: 2019-12-28   12:09
 */
@Service("sysUserService")
public class SysUserServiceImpl extends BaseServiceImpl<SysUserEntity> implements SysUserService {
    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUserEntity findById(String id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public TableDataInfo query(SysUserEntity entity) {
        Page page = new Page(1,10);
        Page mapsPage = sysUserMapper.selectPage(page, null);
        return super.getDataTable(mapsPage);
    }

    @Override
    public String checkLoginNameUnique(String account) {
        SysUserEntity userByAccount = sysUserMapper.getUserByAccount(account);
        if(userByAccount==null){
            return "0";
        }
        return "1";
    }

    @Override
    public String checkPhoneUnique(SysUserEntity user) {
        QueryWrapper queryWrapper=new QueryWrapper(user);
        SysUserEntity entity = sysUserMapper.selectOne(queryWrapper);
        if(entity==null){
            return "0";
        }
        return "1";
    }

    @Override
    public String checkEmailUnique(SysUserEntity user) {
        QueryWrapper queryWrapper=new QueryWrapper(user);
        SysUserEntity entity = sysUserMapper.selectOne(queryWrapper);
        if(entity==null){
            return "0";
        }
        return "1";
    }

    @Override
    public SysUserEntity checkUser(String account) {
        return sysUserMapper.getUserByAccount(account);
    }
}
